//
//  CommunicationTableViewCell.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/4/5.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "CommunicationTableViewCell.h"

@interface CommunicationTableViewCell()<UITextViewDelegate>

@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UITextView *textView;

@end

@implementation CommunicationTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        
        _titleLabel = [UILabel new];
        _titleLabel.font = DEF_FontSize_14;
        NSMutableAttributedString *attStr = [NSMutableAttributedString new];
        NSTextAttachment *imgAtt = [NSTextAttachment new];
        imgAtt.image = [UIImage imageNamed:@"chat"];
        imgAtt.bounds = CGRectMake(0, -2, 15, 15);
        [attStr appendAttributedString:[NSAttributedString attributedStringWithAttachment:imgAtt]];
        [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@" 沟通"]];
        _titleLabel.attributedText = attStr;
        
        _textView = [UITextView new];
        _textView.font = DEF_FontSize_12;
        _textView.text = @"您可以在这里输入";
        _textView.delegate = self;
        _textView.textColor = [UIColor grayColor];
        
        [self.contentView addSubview:_titleLabel];
        [self.contentView addSubview:_textView];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _titleLabel.frame = CGRectMake(10, 0, SCREEN_WIDTH-20, 27);
    _textView.frame = CGRectMake(10, 24, SCREEN_WIDTH - 20 ,self.frame.size.height-27);
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    if ([textView.text isEqualToString:@"您可以在这里输入"]) {
        textView.text = @"";
        textView.textColor = [UIColor blackColor];
    }
    return YES;
}

- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
    if (self.endEditHandle) {
        self.endEditHandle(textView.text);
    }
    if ([textView.text isEqualToString:@""]) {
        textView.text = @"您可以在这里输入";
        textView.textColor = [UIColor grayColor];
    }
    return YES;
}

- (void)setDataDictionary:(NSDictionary *)dataDictionary{
    _dataDictionary = dataDictionary;
    
}

@end
